import { _decorator, Component, Label, Node, Sprite, UITransform, Vec3 } from 'cc';
import { GLOBALUtil } from './GlobalUtil';
import { GLOBALVar } from './GlobalVar';
const { ccclass, property } = _decorator;

@ccclass('PersonalPageInfoManager')
export class PersonalPageInfoManager extends Component {
    //因为InfoNode组件有拿出来独立使用的情况，因此脚本独立撰写
    @property({type: Node, tooltip: "头像"})
    private avatar: Node = null;
    @property({type: Node, tooltip: "昵称"})
    private Nickname: Node = null;
    @property({type: Node, tooltip: "id"})
    private UserID: Node = null;
    @property({ type: Node, tooltip: "designation"})
    designation: Node = null;   
    protected async onEnable() {
        type UserInfo = {
            nickname: string,
            avatar_url: string,
            userID: string,
            designation: JSON,
        }
        // 获取本地缓存的头像昵称信息，更新显示
        try {
            this.avatar.getComponent(Sprite).spriteFrame = GLOBALVar.avatarSpriteCache;
            this.Nickname.getComponent(Label).string = GLOBALVar.nicknameCache;
            const data: UserInfo = await GLOBALUtil.getUserInfo() as any;
            this.UserID.getComponent(Label).string = `ID: ${data.userID}`;
            
            if (data.designation != null) {
                if (data.designation[1000] == 1) {
                    this.designation.active = true;
                }
            }
        } catch (error) {
            console.error(error)
        }
    }
    start() {

    }
    update(deltaTime: number) {
        
    }
}


